<!-- 发票明细查询（按单据） -->
<template>
  <div class="basic_info">
    <div class="info_operation_btn">
      <div class="btn_left">
        <!-- <el-button type="primary" @click="toNewOrder()">新单(N)</el-button> -->
        <el-button @click="toNewOrderValue()" style="width: 100px">查看发票</el-button>
        <el-button @click="exportExcel">导出</el-button>
        <el-button @click="handleShortcutKeyPrint">打印(P)</el-button>
        <!-- <el-checkbox style="margin-left: 8px; margin-right: 8px;" v-model="queryData.hideRedOrder"
          @change="getTableData(1)">隐藏红冲单据</el-checkbox> -->
        <el-checkbox style="margin-left: 8px;" v-model="queryData.hideInvalidOrder"
          @change="getTableData(1)">隐藏作废发票</el-checkbox>
      </div>
      <!-- <div class="btn_right">
        <el-input v-model="queryData.fuzzyQueryParam" placeholder="请输入往来单位\单据编号\商品\关键字搜索" />
        <el-button type="primary" @click="onQuery">搜索</el-button>
        <el-button @click="onRefresh">刷新</el-button>
        <i @click="onShowColumn()" class="set_up el-icon-s-tools"></i>
      </div> -->
    </div>
    <div class="info_content_div">
      <div class="div_table">
        <div class="div_screen">
          <div class="screen_left">
            <div class="custom_item">
              <div class="item_title">往来单位</div>
              <el-tooltip
                effect="dark"
                :content="getDictTextById(gysOptions, queryData.companyId, 'companyName')"
                :enterable="false"
                placement="bottom-start"
                :disabled="this.getHideToolTipById(gysOptions, queryData.companyId, 'companyName')"
              >
                <div class="custom_select_head">
                  <el-select
                    v-model="queryData.companyId"
                    style="width: 100%"
                    filterable
                    ref="gongyingshang"
                    @visible-change="(value) => handleFilterMethod('', 'companyName')"
                    :filter-method="(value) => handleFilterMethod(value, 'companyName')"
                  >
                    <el-option
                      v-for="item in gysOptions"
                      :key="item.id"
                      :label="item.companyName"
                      :value="item.id"
                    ></el-option>
                  </el-select>
                  <div class="custom_more">
                    <i class="el-icon-more" @click.stop="onShowSupplier"></i>
                  </div>
                </div>
              </el-tooltip>
            </div>
            <!-- <div class="custom_item">
              <div class="item_title">仓库</div>
              <div class="custom_select_head">
                <el-select v-model="queryData.storehouseId" ref="cangku" filterable
                  @visible-change="(value) => handleFilterMethod('', 'storehouseName')"
                  :filter-method="(value) => handleFilterMethod(value, 'storehouseName')">
                  <el-option class="add_select" v-for="item in ckOptions" :key="item.id" :label="item.storehouseName"
                    :value="item.id"></el-option>
                </el-select>
              </div>
            </div> -->
            <!-- 经手人 -->
            <div class="custom_item">
              <div class="item_title">经手人</div>
              <div class="custom_select_head">
                <el-select
                  v-model="queryData.sysUserId"
                  style="width: 100%"
                  filterable
                  ref="jingshouren"
                  @visible-change="(value) => handleFilterMethod('', 'realname')"
                  :filter-method="(value) => handleFilterMethod(value, 'realname')"
                >
                  <el-option
                    v-for="item in jsrOptions"
                    :key="item.id"
                    :label="item.realname"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </div>
            </div>
            <div class="custom_item">
              <div class="item_title">单据编号</div>
              <el-tooltip
                effect="dark"
                :content="queryData.orderNumber"
                :enterable="false"
                placement="bottom-start"
                :disabled="queryData.orderNumber.length < 6"
              >
                <div class="custom_select_head">
                  <el-input type="text" v-model="queryData.orderNumber" placeholder="请输入" />
                </div>
              </el-tooltip>
            </div>
          </div>
          <div class="screen_right">
            <div class="item_title">发票日期</div>
            <el-select @change="changeDate" v-model="monthValue">
              <el-option v-for="item in monthOptions" :key="item" :label="item" :value="item"></el-option>
            </el-select>
            <el-date-picker
              v-model="nowDate"
              type="daterange"
              range-separator="~"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="onClickPicker"
              value-format="yyyy-MM-dd"
            ></el-date-picker>
            <el-button type="primary" @click="onQuery">查询</el-button>
            <i @click="onShowColumn()" class="set_up el-icon-s-tools" style="margin-left: 10px"></i>
          </div>
        </div>
        <div class="div_screen">
          <div class="screen_left">
            <!-- <div class="custom_item">
              <div class="item_title">商品名称</div>
              <el-tooltip effect="dark" :content="getDictTextById(spmcOptions, queryData.goodsId, 'goodsName')"
                :enterable="false" placement="bottom-start"
                :disabled="this.getHideToolTipById(spmcOptions, queryData.goodsId, 'goodsName')">
                <div class="custom_select_head">
                  <el-select v-model="queryData.goodsId" style="width:100%;" filterable
                  @visible-change="(value) => handleFilterMethod('', 'goodsName')"
                  :filter-method="(value) => handleFilterMethod(value, 'goodsName')">
                    <el-option v-for="item in spmcOptions" :key="item.id" :label="item.goodsName"
                      :value="item.id"></el-option>
                  </el-select>
                  <div class="custom_more">
                    <i class="el-icon-more" @click.stop="onShowCommodity"></i>
                  </div>
                </div>
              </el-tooltip>
            </div> -->

            <div class="custom_item">
              <div class="item_title">发票类别</div>
              <div class="custom_select_head">
                <el-select v-model="queryData.type">
                  <el-option
                    v-for="item in fplbOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </div>
            </div>
            <div class="custom_item">
              <div class="item_title">发票类型</div>
              <div class="custom_select_head">
                <el-select v-model="queryData.invoiceType">
                  <el-option
                    v-for="item in fplxOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </div>
            </div>
            <div class="custom_item">
              <div class="item_title">开票状态</div>
              <div class="custom_select_head">
                <el-select v-model="queryData.orderInvoiceStatus">
                  <el-option
                    v-for="item in kpztOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </div>
            </div>
          </div>
          <!-- <div class="screen_right">
            <el-checkbox v-model="arrivalDate">到货日期</el-checkbox>
            <el-select @change="changeDateByArrival" v-model="monthArrivalValue" :disabled="!arrivalDate">
              <el-option v-for="item in monthOptions" :key="item" :label="item" :value="item"></el-option>
            </el-select>
            <el-date-picker :disabled="!arrivalDate" v-model="nowDate" type="daterange" range-separator="~"
              start-placeholder="开始日期" end-placeholder="结束日期" @change="onClickPicker"
              value-format="yyyy-MM-dd"></el-date-picker>
            <div style="width:60px;height: 30px;"></div>
          </div> -->
        </div>
        <div class="table_content">
          <el-table
            ref="tableRef"
            show-summary
            :summary-method="getSummaries"
            border
            highlight-current-row
            :header-cell-style="{
              color: '#666666',
              textAlign: 'center',
              height: '30px',
              borderColor: '#dddddd',
            }"
            :data="tableData.records"
            height="100%"
            @selection-change="handleSelectionChange"
            @row-click="onClickRow"
          >
            <!-- <el-table-column type="selection"></el-table-column> -->
            <el-table-column :resizable="false" label="序号" type="index" width="50"></el-table-column>
            <template v-for="(item, index) in columnData">
              <el-table-column
                :show-overflow-tooltip="true"
                border
                :key="index"
                :label="item.zidingyiName ? item.zidingyiName : item.morenName"
                v-if="item.zidingyiState"
                :prop="item.props"
                min-width="150px"
                :sortable="item.sortable"
                :resizable="item.props=='goodsName'?true:false"
                :width="item.props == 'orderNumber' ? '170px' :  ''"
              >
                <template slot-scope="scope">
                  <span v-if="item.props == 'invoicableAmount' || item.props == 'taxAmount' || item.props == 'invoiceTotalAmount' || item.props == 'nowInvoiceAmount' || item.props == 'uninvoicedAmount'">
                    {{
                      $formatMoney(scope.row[item.props]) }}
                  </span>
                  <span
                    v-else-if="item.morenName == '商品名称'"
                    style="
                      width: 100%;
                      white-space: normal;
                      word-wrap: break-word;
                      overflow: hidden;
                      text-overflow: ellipsis;
                      display: -webkit-box;
                      -webkit-line-clamp: 2;
                      -webkit-box-orient: vertical;
                      text-align: left;
                    "
                    >{{ scope.row[item.props] }}</span
                  >
                  <span
                    v-else-if="
                      item.props == 'number' || item.props == 'arrivalNumber' || item.props == 'notArrivalNumber'
                    "
                  >
                    {{ $formatNumber(scope.row[item.props]) }}
                  </span>
                  <span v-else-if="item.props == 'invoicePrice' || item.props == 'goodsPrice'">
                    {{
                      $formatPrice(scope.row[item.props]) }}
                  </span>
                  <span v-else>{{ scope.row[item.props] }}</span>
                </template>
              </el-table-column>
            </template>
          </el-table>
        </div>
        <div class="table_pagination">
          <div class="pagination_div">
            <el-pagination
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[20, 50, 100, 200]"
              :page-size="pagesize"
              layout="jumper, prev, pager,next, sizes"
              :total="tableData.total"
            ></el-pagination>
          </div>
        </div>
      </div>
    </div>
    <!-- 列配置弹框 -->
    <CConfiguration
      ref="setColumnRef"
      :columnDataArr="columnData"
      :defaultColumnDataArr="defaultColumnData"
      orderType="发票明细查询(按商品)"
      @onSaveColumn="onSaveColumn"
    ></CConfiguration>
    <!-- 选择供应商弹框 -->
    <DialogSupplier ref="supplierRef" @onSelectSupplier="onSelectSupplier"></DialogSupplier>
    <!-- 选择商品弹框 -->
    <DialogCommoditySingle ref="commodityRef" @onSelectCommodity="onSelectCommodity"></DialogCommoditySingle>
    <!-- 生成采购单 -->
    <DialogGenerateSalesOrder ref="generateSalesOrderRef" :orderData="orderData" billType="采购">
    </DialogGenerateSalesOrder>
    <!-- 打印 -->
    <dialog-print ref="print"></dialog-print>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import CConfiguration from '@/components/c_column/columnConfiguration1'
import DialogSupplier from '../../components/dialogSupplier'
import DialogCommoditySingle from '@/views/components/dialogCommoditySingle'
import DialogSupplierAdd from '../../components/dialogSupplierAdd'
import DialogStaffAdd from '../../components/dialogStaffAdd'
/**打印 */
import dialogPrint from '@/views/components/dialogPrintRecord'
import DialogGenerateSalesOrder from '../../components/dialogGenerateSalesOrder'
import { getAction, postAction } from '@/api/manage'
import { delcommafy, formatMoney, formatNumber, formatPrice } from '../../../utils'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
// 导入调用处理权限数据方法
import { handlePermissions, handleOtherPerms, handlePagePermissions } from '@/utils/index'
export default {
  name: 'orderDetailsQuery',
  mixins: [JeecgListMixin],
  components: {
    CConfiguration,
    DialogSupplier,
    DialogSupplierAdd,
    DialogStaffAdd,
    DialogGenerateSalesOrder,
    DialogCommoditySingle,
    dialogPrint,
  },
  computed: {
    ...mapGetters(['name']),
    buttonsPermissions() {
      return handlePermissions('发票明细查询')
    },
    printPermissions() {
      return handleOtherPerms('单据可多次打印')
    },
  },
  created() {
    this.getData()
    // this.buttonsPermissions = handlePermissions('发票明细查询')
  },
  watch: {
    tableData: {
      immediate: true,
      handler() {
        setTimeout(() => {
          const table = document.querySelector('.el-table__footer-wrapper>table')
          let tds = table.rows[0].cells
          tds[1].colSpan = 2
          tds[2].style.display = 'none'
          let cell = tds[1].childNodes[0]
          cell.style.justifyContent = 'flex-start'
          cell.style.paddingLeft = '5px'
        }, 0)
      },
    },
  },
  updated() {
    this.$nextTick(() => {
      this.$refs['tableRef'].doLayout()
    })
  },
  data() {
    return {
      orderData: [], // 传递给生成销售单的数据
      // 存储按钮权限数据
      // buttonsPermissions: {},
      // 供应商
      gysOptions: [],
      ckOptions: [], // 仓库
      spmcOptions: [], //商品名称
      // 经手人
      jsrOptions: [],
      // 发票类别
      fplbOptions: [
        {
          value: '',
          label: '全部',
        },
        {
          value: 0,
          label: '进项发票',
        },
        {
          value: 1,
          label: '销项发票',
        },
      ],
      // 发票类型
      fplxOptions: [
        {
          value: '',
          label: '全部',
        },
        {
          value: 1,
          label: '普通发票',
        },
        {
          value: 2,
          label: '增值税专票',
        },
      ],
      // 开票状态
      kpztOptions: [
        {
          value: '',
          label: '全部',
        },
        {
          value: 0,
          label: '已开完',
        },
        {
          value: 1,
          label: '未开完',
        },
      ],
      // 查询条件数据
      queryData: {
        // 直接触发
        hideRedOrder: false,
        hideInvalidOrder: false,
        startTime: '', // 开始时间
        endTime: '', //结束时间
        companyId: '', // 供应商id
        // fuzzyQueryParam: '', // 单据编号/往来单位
        // goodsId: '',
        orderNumber: '',
        // storehouseId: '',
        sysUserId: '', // 经手人id
        // status: '',
        // arrivalTimeBegin: '',
        // arrivalTimeEnd: '',
        type: '', // 发票类别
        invoiceType: '', // 发票类型
        orderInvoiceStatus: '', // 开票状态
      },
      // 月份选择
      monthValue: '本月',
      monthOptions: ['今天', '昨天', '本周', '上一周', '本月', '上一月', '本年', '去年'],
      nowDate: [],
      monthArrivalValue: '本月',
      nowArrivalDate: [],
      arrivalDate: false, //是否使用到货日期查询
      // 表格数据
      tableData: {},
      // 列配置数据
      defaultColumnData: [],
      columnData: [
        {
          morenName: '单据日期',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'orderTime',
        },
        {
          morenName: '单据编号',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'orderNumber',
        },
        {
          morenName: '往来单位名称',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'xghCompanyId_dictText',
        },
        {
          morenName: '经手人',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'sysUserId_dictText',
        },
        {
          morenName: '商品名称',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'goodsId_dictText',
        },
        {
          morenName: '商品编号',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'goodsNumber',
        },
        {
          morenName: '单价',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'goodsPrice',
        },
        {
          morenName: '可开发票金额',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'invoicableAmount',
        },
        {
          morenName: '税额',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'taxAmount',
        },
        {
          morenName: '发票总金额',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'invoiceTotalAmount',
        },
        {
          morenName: '开票金额',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'nowInvoiceAmount',
        },
        {
          morenName: '未开金额',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'uninvoicedAmount',
        },
        {
          morenName: '单据状态',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'orderStatus_dictText',
        },
        {
          morenName: '单据备注',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'orderRemark',
        },
        {
          morenName: '发票号码',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'invoiceNumber',
        },
        {
          morenName: '发票类型',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'invoiceType_dictText',
        },
        {
          morenName: '发票备注',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'remark',
        },
        {
          morenName: '发票日期',
          zidingyiName: '',
          morenState: true,
          zidingyiState: true,
          noModify: false,
          props: 'invoiceDate',
        },
      ],

      batchData: [], // 存储多选的数据
      pagesize: 20, //每页的数据条数
      currentPage: 1, //默认开始页面
      updateId: '', // 修改列配置时返回的id

      url: {
        listUrl: '/xghInvoiceInfo/xghInvoiceInfo/invoiceInfoQuery',
        api: '发票明细查询(按商品)',
        exportXlsUrl: '/xghInvoiceInfo/xghInvoiceInfo/exportInvoiceInfos',
      },
      billName: '发票明细查询(按商品)',
      // 选中的数据
      selectData: {},
    }
  },
  mounted() {},
  methods: {
    // 打印
    async handleShortcutKeyPrint() {
      // 查询
      let data = {
        ...this.queryData,
        // arrivalTimeBegin: this.arrivalDate ? this.queryData.arrivalTimeBegin : '',
        // arrivalTimeEnd: this.arrivalDate ? this.queryData.arrivalTimeEnd : '',
        pageSize: 1000000,
        pageNo: 1,
        xghCompanyId: this.queryData.companyId, // 供应商id
        invoiceWay: 0, // 0-按商品 1-按单据
        invoiceStatus: this.queryData.hideInvalidOrder? 0 : '',
      }
      let printExclusive = []
      const res = await getAction(this.url.listUrl, data)
      if (res.code !== 200) {
        return this.$elMessage.error('获取数据失败！')
      }
      printExclusive = res.result.records || []
      // printExclusive.forEach((item) => {
      //   item.isReplacementOrder = item.isReplacementOrder == '1' ? '否' : '是'
      // })
      // const pricearr = ['price', 'goodsPrice', 'discountUnitPrice']
      // const monarr = ['allPrice', 'arrivalAmount', 'terminationAmount', 'notArrivalAmount','purchaseOrderPrice','depositPrice', 'taxPrice']
      // const numarr = ['number', 'arrivalNumber', 'notArrivalNumber']
      // printExclusive = (res.result.records || []).map((item) => {
      //   // 遍历 item 对象的键
      //   Object.keys(item).map((key) => {
      //     if (numarr.includes(key)) {
      //       item[key] = formatNumber(item[key])
      //     } else if (monarr.includes(key)) {
      //       item[key] = formatMoney(item[key])
      //     } else if (pricearr.includes(key)) {
      //       item[key] = formatPrice(item[key])
      //     }
      //   })
      //   return item
      // })
      // this.onQuery()
      // 打印
      // if (!this.buttonsPermissions.DaYin) {
      //   this.$elMessage.warning('未拥有打印权限！')
      // } else
      if (!printExclusive || printExclusive.length <= 0) {
        this.$elMessage.warning('没有要打印的记录！')
      } else {
        let printData = {
          riqi: this.queryData.startTime + '~' + this.queryData.endTime,
          gongyingshang: this.$refs.gongyingshang.selected.label,
          // cangku: this.$refs.cangku.selected.label,
          jingshouren: this.$refs.jingshouren.selected.label,
          printExclusive,
        }
        // 可以多次打印设置
        if (this.printPermissions) {
          this.$refs.print.show(printData, this.columnData, this.billName)
        } else {
          if (this.$lcStorage.get('printLimitValue')) {
            // 获取打印次数
            this.getPrintNum(this.billName, () => {
              this.$refs.print.show(printData, this.columnData, this.billName)
            })
          } else {
            this.$refs.print.show(printData, this.columnData, this.billName)
          }
        }
      }
    },
    // 选中当前行
    onClickRow(row) {
      this.selectData = row
      this.$refs.tableRef.toggleRowSelection(row)
    },
    // 双击列表
    // handleRowDbclick(row) {
    //   this.$toBillDetail(this, '1', row.id)
    // },
    // 初始化获取数据
    getData() {
      this.getTimeRange(this.$setTimeRange(5)) // 默认获取当月时间
      this.changeDateByArrival(5)
      this.getGysStorage() // 获取供应商信息数据
      this.getStaffData() // 获取经手人信息数据
      // this.getWarehouseData()
      this.getTableData(1) // 获取表格信息数据
      this.getGoodsNameList()
      // this.selectTitle()
    },
    // 初始化查询列配置值
    async selectTitle() {
      let obj = await this.$setColumn.selectColumn(this.url.api)
      if (obj.code === 200) {
        this.updateId = obj.updateId
        this.columnData = obj.columnData
      } else if (obj.code === 500) {
        let id = await this.$setColumn.addColumn(this.url.api, this.columnData, 0, this.updateId)
        this.updateId = id
      }
    },
    // 修改列配置后保存修改后的值
    async onSaveColumn(value) {
      this.columnData = value
      let res = await this.$setColumn.editColumn(this.url.api, this.columnData, this.updateId)
      if (res.code == 200) {
        this.$elMessage.success(res.message)
      } else {
        this.$elMessage.error(res.message)
      }
    },
    // 触发列配置弹框
    onShowColumn() {
      this.defaultColumnData = this.$options.data().columnData
      this.$refs.setColumnRef.dialogVisible = true
    },
    // 打开选择商品弹出框
    onShowCommodity() {
      this.$refs.commodityRef.dialogVisible = true
    },
    // 当前选择商品数据
    onSelectCommodity(val) {
      this.queryData.goodsName = val.goodsName
    },
    // 获取表格信息数据
    async getTableData(page) {
      if (page == 1) {
        this.currentPage = 1
      }
      let data = {
        ...this.queryData,
        // arrivalTimeBegin: this.arrivalDate ? this.queryData.arrivalTimeBegin : '',
        // arrivalTimeEnd: this.arrivalDate ? this.queryData.arrivalTimeEnd : '',
        pageSize: this.pagesize,
        pageNo: this.currentPage,
        xghCompanyId: this.queryData.companyId, // 供应商id
        invoiceWay: 0, // 0-按商品 1-按单据
        invoiceStatus: this.queryData.hideInvalidOrder ? 0 : '',
      }
      const res = await getAction(this.url.listUrl, data)
      if (res.code !== 200) {
        return this.$elMessage.error('获取数据失败！')
      }
      this.tableData = res.result
      this.tableData.records.forEach((item) => {
        item.invoicableAmount = formatMoney(item.invoicableAmount)
        item.notArrivalAmount = formatMoney(item.notArrivalAmount)
        item.terminationAmount = formatMoney(item.terminationAmount)
        item.arrivalAmount = formatMoney(item.arrivalAmount)
        item.purchaseOrderPrice = formatMoney(item.purchaseOrderPrice)
        item.isReplacementOrder = item.isReplacementOrder == '1' ? '否' : '是'
      })
    },
    // 初始化默认获取缓存中存储的曾经点击过的供应商数据
    getGysStorage() {
      getAction('/xghCompany/xghCompany/listNoPage', {}).then((res) => {
        if (res.code === 200) {
          this.gysOptions = res.result
          this.totalCompanys = res.result
        } else {
          this.$elMessage.error(res.message)
        }
      })
    },
    // 获取所有经手人数据
    async getStaffData() {
      getAction('/dept/xghAccountBookDept/getAllDeptUsers', {}).then((res) => {
        if (res.code === 200) {
          this.jsrOptions = res.result
          this.totalPersons = res.result
        } else {
          this.$elMessage.error(res.message)
        }
      })
    },
    // 获取所有仓库数据
    // getWarehouseData() {
    //   getAction('/xghStorehouse/xghStorehouse/queryListByPole', {}).then((res) => {
    //     if (res.code === 200) {
    //       this.ckOptions = res.result
    //       this.totalStores = res.result
    //     } else {
    //       this.$elMessage.error(res.message)
    //     }
    //   })
    // },
    getGoodsNameList() {
      getAction('/xghGoods/xghGoods/getGoodsNameList', {}).then((res) => {
        if (res.code === 200) {
          this.spmcOptions = res.result
          this.totalGoods = res.result
        } else {
          this.$elMessage.error(res.message)
        }
      })
    },
    handleShortcutKeyAdd() {
      this.toNewOrder()
    },
    // 新单 跳转至采购入库单 单据页面
    toNewOrder() {
      if (!handlePagePermissions('采购订单')) {
        return this.$elMessage.warning('没有权限！')
      }
      this.$router.push({
        path: '/purchaseManage/purchaseBill/billPurchaseOrder',
      })
    },
    // 新单 跳转至售出库单 单据页面(需传值)
    toNewOrderValue() {
      const invoiceId = this.selectData.invoiceId
      const invoiceWay = this.selectData.invoiceWay
      let url = ''
      let name = ''
      if (invoiceId && invoiceId.length > 0) {
        if (this.selectData.type == 0) {
          this.$router.push({
            name: 'invoicesManage-invoicesStatistics-incomingInfo',
            params: {
              invoiceId,
              invoiceWay,
            },
          })
        } else {
          this.$router.push({
            name: 'invoicesManage-invoicesStatistics-outgoingInfo',
            params: { invoiceId, invoiceWay },
          })
        }
      } else {
        this.$elMessage.warning('请先选择单据！')
      }
    },
    // 查询
    onQuery() {
      this.getTableData(1)
    },
    // 刷新
    onRefresh() {
      Object.assign(this.$data, this.$options.data())
      // this.buttonsPermissions = handlePermissions('发票明细查询')
      this.getData()
    },
    // 打开选择供应商弹出框
    onShowSupplier() {
      this.$refs.supplierRef.dialogVisible = true
    },
    // 当前选择供应商数据
    onSelectSupplier(val) {
      this.queryData.companyId = val.id
    },
    changeDateByArrival(val) {
      let index = 5
      switch (val) {
        case '今天':
          index = 1
          break
        case '本周':
          index = 3
          break
        case '本月':
          index = 5
          break
        case '本年':
          index = 7
          break
        default:
          break
      }
      // let date = this.$setTimeRange(index)
      // this.nowArrivalDate = [date.now, date.end]
      // this.queryData.arrivalTimeBegin = date.now
      // this.queryData.arrivalTimeEnd = date.end
    },
    // 判断当前选择时间段
    changeDate(val) {
      switch (val) {
        case '全部':
          this.queryData.startTime = ''
          this.queryData.endTime = ''
          break
        case '今天':
          this.getTimeRange(this.$setTimeRange(1))
          break
        case '昨天':
          this.getTimeRange(this.$setTimeRange(2))
          break
        case '本周':
          this.getTimeRange(this.$setTimeRange(3))
          break
        case '上一周':
          this.getTimeRange(this.$setTimeRange(4))
          break
        case '本月':
          this.getTimeRange(this.$setTimeRange(5))
          break
        case '上一月':
          this.getTimeRange(this.$setTimeRange(6))
          break
        case '本年':
          this.getTimeRange(this.$setTimeRange(7))
          break
        case '去年':
          this.getTimeRange(this.$setTimeRange(8))
          break
        default:
          break
      }
    },
    // 获取时间范围并设置
    getTimeRange(data) {
      this.nowDate = [data.now, data.end]
      this.queryData.startTime = data.now
      this.queryData.endTime = data.end
    },
    // 获取当前选中时间
    onClickPicker(val) {
      this.queryData.startTime = val[0]
      this.queryData.endTime = val[1]
    },
    // 合计列计算
    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      const arr = [
        'taxPrice',
        'allPrice',
        'depositPrice',
        'purchaseOrderPrice',
        'number',
        'arrivalNumber',
        'notArrivalNumber',
      ]
      const monarr = ['taxPrice', 'allPrice', 'depositPrice', 'purchaseOrderPrice']
      const numarr = ['number', 'arrivalNumber', 'notArrivalNumber']
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
        } else if (index === 1) {
          sums[index] = '共' + this.tableData.total + '条明细'
        } else if (arr.includes(column.property)) {
          const values = data.map((item) => delcommafy(item[column.property]))
          if (!values.every((value) => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = delcommafy(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            if (monarr.includes(column.property)) {
              sums[index] = this.$formatMoney(sums[index])
            } else if (numarr.includes(column.property)) {
              sums[index] = this.$formatNumber(sums[index])
            } else {
              sums[index] = this.$formatPrice(sums[index])
            }
          }
        } else {
          sums[index] = ''
        }
      })
      return sums
    },
    // 获取每页几条数据
    handleSizeChange(val) {
      this.pagesize = val
      this.getTableData(1)
    },
    // 获取当前第几页
    handleCurrentChange(val) {
      this.currentPage = val
      this.getTableData()
    },
    // 历史记录数据去重并只展示三个数据方法
    selectDataHas(arr) {
      let map = new Map()
      for (const item of arr) {
        if (!map.has(item.id)) {
          map.set(item.id, item)
        }
      }
      let newArr = [...map.values()]
      return newArr.slice(0, 3)
    },
    // 触发表格多选按钮
    handleSelectionChange(val) {
      this.batchData = val
    },
    // 导出
    exportExcel() {
      let params = {
        invoiceWay: 0,
        invoiceStatus: this.queryData.hideInvalidOrder ? 0 : '',
      }
      this.handleExportXlsByStaff(this.url.api, params)
    },
    // 搜索
    handleFilterMethod(value, label) {
      if (label == 'companyName') {
        this.gysOptions = this.filterMethod(this.gysOptions, value, label)
      } else if (label == 'storehouseName') {
        this.ckOptions = this.filterMethod(this.ckOptions, value, label)
      } else if (label == 'realname') {
        this.jsrOptions = this.filterMethod(this.jsrOptions, value, label)
      } else if (label == 'goodsName') {
        this.spmcOptions = this.filterMethod(this.spmcOptions, value, label)
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.basic_info {
  width: 100%;
  height: calc(100vh - 102px);
  background: #f0f2f5;
  box-sizing: border-box;
  padding: 0 0.168761rem 0.168761rem;
  display: flex;
  flex-direction: column;
}

.info_operation_btn {
  width: 100%;
  height: 60px;
  display: flex;
  align-items: center;

  .el-button {
    width: 70px;
    height: 30px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    border-radius: 5px;
    border: none;
    margin-right: 6px;
  }

  .el-button--default {
    color: #666;
  }

  .btn_left {
    width: 60%;
    display: flex;
    justify-content: flex-start;
    align-items: center;

    p {
      font-size: 12px;
      color: #666;
      margin: 0 0.1rem 0 0.187512rem;
    }

    ::v-deep .el-checkbox__label {
      font-size: 12px;
      padding-left: 5px;
      color: #666;
    }

    ::v-deep .el-select {
      width: 70px;
      height: 40px;
      box-sizing: border-box;
      margin-right: 0.187512rem;

      .el-input {
        .el-input__inner {
          height: 40px;
          border: none;
          font-size: 12px;
        }

        .el-input__suffix {
          height: 40px;
          display: flex;
          align-items: center;
        }
      }
    }

    .selectSty {
      width: 2.625164rem;
    }
  }

  .btn_right {
    width: 40%;
    display: flex;
    justify-content: flex-end;
    align-items: center;

    .el-input {
      width: 250px;
      height: 30px;
      margin-right: 0.112507rem;

      ::v-deep .el-input__inner {
        height: 30px;
        border: none;
        box-sizing: border-box;
        padding: 0 0.15rem;
        background: #fff;
        font-size: 12px;
        color: #666;

        &::placeholder {
          font-size: 12px;
          color: #c1c1c1;
        }
      }
    }

    .set_up {
      font-size: 23px;
      color: rgb(153, 153, 153);
    }
  }
}

.info_content_div {
  width: 100%;
  height: calc(100% - 60px);
  background: #fff;
  box-sizing: border-box;
  padding: 10px;
  display: flex;

  .div_table {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: all 0.3s;

    .div_screen {
      width: 100%;
      height: 50px;
      // margin-bottom: 10px;
      display: flex;
      justify-content: space-between;

      .screen_left {
        font-size: 12px;
        box-sizing: border-box;
        display: flex;
        justify-content: flex-start;
        flex-wrap: wrap;
        min-width: 600px;
      }

      .screen_right {
        margin-right: 20px;
        box-sizing: border-box;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        box-sizing: border-box;

        ::v-deep .el-checkbox__label {
          font-size: 12px;
          // padding-left: 0.1rem;
        }

        ::v-deep .el-button {
          width: 60px;
          height: 30px;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 12px;
          border-radius: 5px;
          border: none;
        }

        ::v-deep .el-select {
          width: 80px;
          margin: 0 10px;

          .el-input {
            .el-input__inner {
              height: 30px;
              border-color: #e3e3e3;
              font-size: 12px;
              padding-left: 5px;
            }

            .el-input__suffix {
              height: 30px;
              display: flex;
              align-items: center;
            }
          }
        }

        ::v-deep .el-date-editor {
          width: 220px;
          height: 30px;
          background: #ffffff;
          border: 1px solid #d9d9d9;
          margin-right: 0.112507rem;
          padding: 3px 6px;

          .el-range__icon {
            position: absolute;
            right: 0;
            line-height: 30px;
          }

          .el-range-separator {
            line-height: 24px;
          }

          .el-range-input {
            font-size: 12px;
          }

          .el-range__close-icon {
            display: none;
          }
        }
      }
    }

    .table_content {
      height: calc(100% - 150px);
      padding-top: 10px;

      ::v-deep .el-table {
        border: 1px solid #e3e3e3;
        border-bottom: none;
        box-sizing: border-box;
        height: 100%;

        th,
        td {
          padding: 0;
          color: #666;
          box-sizing: border-box;
          border-right: 1px solid #e3e3e3;

          .cell {
            line-height: 30px;
            display: flex;
            align-items: center;
            font-size: 12px;
          }

          &:first-child {
            .cell {
              justify-content: center;
              padding: 0;
            }
          }

          &:nth-child(2) {
            .cell {
              justify-content: center;
            }
          }

          &:last-child {
            .cell {
              justify-content: center;
            }
          }
        }

        th {
          .cell {
            // background: #ededed;
            justify-content: center;
          }
        }

        .el-checkbox {
          .is-indeterminate {
            .el-checkbox__inner {
              color: #1b93f9;
              background-color: #1b93f9;
              border-color: #1b93f9;
            }
          }
        }

        .el-icon-edit-outline {
          font-size: 0.25rem;
          color: #1b93f9;
          margin-right: 0.037502rem;
        }

        .el-icon-delete {
          font-size: 0.25rem;
          color: #ff2626;
          margin-left: 0.037502rem;
        }

        .el-table__body tr:hover > td {
          background: #e3f6ff;
        }

        .el-table__footer-wrapper {
          td {
            background: #f4f4f4;
            border: none;
          }
        }

        .el-table__header {
          tr {
            &:last-child {
              th {
                background: rgb(237, 237, 237) !important;
              }
            }
          }
        }

        //滚动条的宽度
        ::-webkit-scrollbar {
          width: 8px;
          height: 10px;
          background-color: #e5e5e5;
        }

        //滚动条的滑块
        ::-webkit-scrollbar-thumb {
          background-color: #c9c9c9;
        }
      }
    }

    .table_pagination {
      .total {
        margin-top: 0.25rem;
        width: 3.750234rem;
        font-size: 12px;
        color: #666666;
      }

      width: 100%;
      height: 50px;
      box-sizing: border-box;
      padding: 10px 0;
      display: flex;

      .pagination_div {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: flex-end;

        ::v-deep .el-pagination {
          padding: 0;
          height: 30px;

          .el-pagination__sizes {
            margin: 0;

            .el-input {
              margin-right: 0;
            }
          }
        }
      }
    }
  }
}

.custom_item {
  display: flex;
  align-items: center;
  margin: 10px 10px 10px 0;
  width: 180px;
  font-size: 12px;
}

.item_title {
  padding: 0 5px;
  width: auto;
  min-width: 60px;
  line-height: 30px;
  color: #666666;
  text-justify: distribute-all-lines;
  /*ie6-8*/
  text-align-last: justify;
  /* ie9*/
  -moz-text-align-last: justify;
  /*ff*/
  -webkit-text-align-last: justify;
  /*chrome 20+*/
}

.custom_select_head {
  flex: 1;
  height: 30px;
  position: relative;

  ::v-deep .el-select {
    .el-input {
      .el-input__inner {
        height: 30px;
        border-color: #e3e3e3;
        font-size: 12px;
        padding-left: 5px;
      }

      .el-input__suffix {
        height: 30px;
        display: flex;
        align-items: center;
      }
    }
  }

  ::v-deep .el-input {
    width: 100%;

    .el-input__inner {
      height: 30px;
      border-color: #e3e3e3;
      font-size: 12px;
      padding-left: 5px;
    }

    .el-input__suffix {
      height: 30px;
      display: flex;
      align-items: center;
    }
  }
}

.custom_more {
  position: absolute;
  right: 10px;
  z-index: 10;
  top: 1px;
  background: #fff;
  height: 28px;
  display: flex;
  align-items: center;
  color: #bfbfbf;
}

.custom_add {
  display: flex;
  justify-content: center;
  align-items: center;

  span {
    margin-left: 5px;
    color: #666666;
  }

  i {
    color: #666666;
  }
}

.disabled_button {
  background: #cbced3 !important;
  color: #666 !important;
}
</style>